<?php 
$peer = OrdersPeer::getInstance();
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');

/* @var $order OrdersRow */
$order = $peer->find($id)->current();
if (!$order) $order = OrdersPeer::getInstance()->createRow();

$placed = OrdersService::getInstance()->getOrderStatusByKey(OrdersService::STATUS_ORDER_PLACED);
$form = $this->element;

// payment method
$payment = $form->getElement('payment_method_id');
$default = PaymentMethodsPeer::getInstance()->findByKey('cash')->current();
if (!$payment->getValue()) {
	$payment->setValue($default->getId());
}

$current = $payment->getValue();
foreach ($payment->getMultiOptions() as $key => $value) {
	if ($key != $current) $payment->removeMultiOption($key);
}

// type
$type = $form->getElement('type_id');
$type->setLabel(null);
$type->setDecorators(array('ViewHelper'));
$default = OrderTypePeer::getInstance()->fetchByKey('operator');
if (!$type->getValue()) {
	$type->setValue($default->getId());
}

$current = $type->getValue();
foreach ($type->getMultiOptions() as $key => $value) {
	if ($key != $current) $type->removeMultiOption($key);
}
$type->setAttrib('style', 'display:none;');

// delivery_time
$deliveryTime = $form->getElement('delivery_time_id');
if (!$order->getId()) {
	$options = $deliveryTime->getMultiOptions();
	$deliveryTime->clearMultiOptions();
	$deliveryTime->addMultiOption(null);
	$deliveryTime->addMultiOptions($options);
}


$elements = $form->getElements();
foreach ($elements as $key => $element) {
	if ($element->class == 'wysiwyg' || $element->class == 'map') {
		$element->class = '';
	}
	
}

foreach (array(
	'operator_id', 
	'executed_at', 
	'delivery_time_id', 
	'payment_method_id',
	) as $element) {
		$el = $form->$element;
		$el->removeDecorator("HtmlTag");
		$el->getDecorator("Label")->setTag(null);
}

if (!$order->isModifiedAvailable()) {
	foreach ($form->getElements() as $element) {
		if ($element->class == 'date') $element->class = '';
		$element->setAttrib('readonly', 'readonly');
	}
}

?>

<style media="screen" type="text/css">
    .defaultText { width: 100px; }
    .defaultTextActive { color: #a1a1a1; font-style: italic; }
    fieldset { padding:10px; }
    fieldset legend { font-size:14px; font-weight:bold; color:gray; }
    .orderedit td { padding:4px; }
    .orderedit thead,.orderedit tfoot { font-size:14px; font-weight:bold;}
    .listorder { border-right:1px solid gray; border-bottom:1px solid gray; }
    .orderedit .td1 { text-align:left; width:50%; border-left:1px solid gray; border-top:1px solid gray;}
    .orderedit .td2 { text-align:center; width:10%; border-left:1px solid gray; border-top:1px solid gray;}
    .orderedit label { font-weight:bold; }
    .comment { padding:10px; border-left:1px dashed gray; margin-bottom:10px; }
</style>

<form action="" method="post" id="form_cc">

	<?php echo $form->type_id; ?>
    <h2>
    	<?php 
    		if ($order->getId()) {
    			echo "Заказ №{$order->getId()}";
    			$timestamp = strtotime($order->getCreatedAt()); 
    			echo ' от ' . date("d F Y (H:i)", $timestamp);
    		} else {
    			echo "Новый заказ";
    		}
    	?>
    </h2>
    <?php 
    if ($order->getId()) {
    	$statusRow = $order->getOrderStatusRowByOrderStatusId();
    	echo "<h3>Статус: {$statusRow->getName()}</h3>";
    }
    ?>
    <br />
    <?php 
	$delivery = $order->getDeliveryRowByDeliveryId();
	if (!$delivery) {
		$delivery = DeliveryPeer::getInstance()->createRow();
	}
	
	// Show logs
	if ($order->getId()) {
    	$rowset = $order->getOrderLogRowsetByOrderId();
    	if ($rowset->count()) {
	    	echo '<p class="comment">';
		    foreach ($rowset as $row) {
		    	$message = $row->getMessage();
		    	
		    	$userId = $row->getAdminUserId();
		    	if ($userId) {
			    	$user = AdminUserPeer::getInstance()->find($userId)->current();
			    	$name = $user->getName() ? $user->getName() : $user->getLogin();
			    	
			    	$message = sprintf($message, $name);
		    	}
		    	
		   		$time = strtotime($row->getCreated());
		   		$time = date("d.m.Y в H:i", $time);
		   		echo "[$time] $message<br />";
		    }
		    echo '</p>';
    	}
    }
    
    /**
     * Translate some form errrors.
     * 
     * @param string $key
     * @param string $error
     * @return string
     */
    function _translate($key, $error)
    {
    	$_translated = array(
			'isEmpty' => 'Поле обязательно для заполнения',
		);
	
    	if (isset($_translated[$key])) {
    		return $_translated[$key];
    	}
    	
    	return $error;
    }
    
    $errors = $form->getMessages();
    foreach ($errors as $key => $error) {
    	if (is_array($error)) {
    		unset($errors[$key]);
    	}

   		if (is_array($error)) {
     		foreach ($error as $k => $v) {
     			$label = $form->getElement($key)->getLabel();
     			$v = _translate($k, $v);
     			$errors[$key][$k] = "$label -- $v";
     		}
    	} else {
    		$errors[$key] = _translate($key, $error);
    	}
    }
    
    if ($errors) {
	    echo "<ul class='errors'>";
	    foreach ($errors as $error) {
	    	if (is_array($error)) {
	    		foreach ($error as $k => $v) {
	    			echo "<li>$v</li>";
	    		}
	    	} else {
	    		echo "<li>$error</li>";
	    	}
	    }
	    echo "</ul>";
    }
    ?>
    
    <fieldset>
<script>
$(function() {
	$("#create_user").click(function() {
		var $email = $("#email");
		if (!$email.val()) {
			alert('Заполните хотя бы электронный адрес для создания нового пользователя');
			return false;
		}

		var $columns = [
			'email', 
			'firstName', 
			'lastName', 
			'phone', 
			'suggest_city', 
			'suggest_street', 
			'home', 
			'corps', 
			'porch', 
			'level',
			'flat'
		]

		var $data = '';
		for (var $key in $columns) {
			var $column = $columns[$key];
			var $value = $("#" + $column).val();
			
			$data += $column + '=' + $value + '&';
		}

		$.ajax({
			url: '/admin/call-center/create-user/orderId/<?php echo $id; ?>',
			type: 'post',
			data: $data,
			dataType: 'json',
			success: function($data) {
				if ($data.result == 'failure') {
					alert($data.message);
					return false;
				}

				$("#create_user").remove();
				$("#is_registered").text("Да");
				alert('Пользователь создан');
				return false;
			}
		});

		return false;
	});
});
</script>

<?php 
$registered = 0;
        	$profile = $order->getProfileRowByProfileId();
        	if ($profile) {
        		$email = $profile->getEmail();
        		if (($email == 'h@detmir.ru') || ($email == 'frontend@detmir.ru')) {
        			$registered = 0;
        		} else {
        			$registered = 1;
        		}
        	} else {
        		$registered = 0;
        	}
?>
            
	<legend>Информация о клиенте 

	</legend>
	<table cellpadding="0" cellspacing="0" border="0" class="orderedit">
	    <tr>
			<td>
				<?php 
				$input = new Zend_Form_Element_Text('firstName');
				$input->setLabel('Имя:');
				$input->setRequired(1);
				$input->setDecorators(array('ViewHelper', 'Label'));
				$input->setAttrib('default', $delivery->getFirstName());
				if (!$order->isModifiedAvailable()) {
					$input->setAttrib('readonly', 'readonly');
				}
				
				echo $input;
				?>
			</td>
			<td>
				<?php 
				$input = new Zend_Form_Element_Text('lastName');
				$input->setLabel('Фамилия:');
				$input->setRequired(1);
				$input->setDecorators(array('ViewHelper', 'Label'));
				$input->setAttrib('default', $delivery->getLastName());
				if (!$order->isModifiedAvailable()) {
					$input->setAttrib('readonly', 'readonly');
				}
				
				echo $input;
				?>
			</td>
			<td>
				<?php 
				$input = new Zend_Form_Element_Text('email');
				$input->setLabel('Email:');
				$input->setDecorators(array('ViewHelper', 'Label'));
				$input->setAttrib('default', $delivery->getEmail());
				if (!$order->isModifiedAvailable()) {
					$input->setAttrib('readonly', 'readonly');
				}
				
				echo $input;
				?>
			</td>
			<td>
				<?php
				$input = new Zend_Form_Element_Text('phone');
				$input->setLabel('Телефон:');
				$input->setRequired(1);
				$input->setDecorators(array('ViewHelper', 'Label'));
				$input->setAttrib('default', $delivery->getPhone());
				if (!$order->isModifiedAvailable()) {
					$input->setAttrib('readonly', 'readonly');
				}

				echo $input;
				?>
			</td>
			
			<td>
				
				<label class="required" for="type_id">Тип заказа</label>				
				<select id="type_id" name="type_id">
				<option label="" value=""></option>
				<?php
			        $order_type = OrderTypePeer::getInstance()->fetchAll();
					
					foreach($order_type as $type)
					{
						if ($order->getTypeId() == $type->getId()) {
							echo '<option selected="selected" label="'.$type->getName().'" value="'.$type->getId().'">'.$type->getName().'</option>';
						} else {
							echo '<option label="'.$type->getName().'" value="'.$type->getId().'">'.$type->getName().'</option>';
						}					
					}					
			    ?>
				</select>
				
				
			</td>
				<td>
					
					
				<?php
				$input = new Zend_Form_Element_Text('wikimart');
				$input->setLabel('Номер заказа:');
				//$input->setRequired(1);
				$input->setDecorators(array('ViewHelper', 'Label'));
				$input->setAttrib('default', $order->getWikimart());
				if (!$order->isModifiedAvailable()) {
					$input->setAttrib('readonly', 'readonly');
				}
				echo $input;
				?>
				
				
					    
	    
			</td>
			
	    </tr>
	    <tr>
		<td>
			<label>
				<a target="_blank" href='<?php echo $this->url(array('table' => 'profile', 'id' => null, 'action' => 'list')); ?>'>
					Найти пользователя
				</a>
			</label>
			<br />
            <label>Зарегистрирован: <span id='is_registered'>
            <?php 
            	echo ($registered) ? 'Да' : 'Нет';
            ?></span>
            </label>
            <br />
		    <label>Общее количество заказов:
		    <?php 
		    		if ($profile) {
						$query = "select count(*) as count from orders where profile_id = {$profile->getId()}";
						$stmt = Db::getConnection()->query($query);
						$count = $stmt->fetchColumn();
						echo $count;
		    		} else {
		    			echo '-';
		    		}

		    ?></label>
        </td>
	    </tr>
	</table>
    </fieldset>
    <fieldset>
        <legend>Оплата</legend>

        <table cellpadding="0" cellspacing="0" border="0" class="orderedit">
            <tr>
                <td>
                    <?php 
                    $pm = $form->payment_method_id;
                    $payment = current($pm->getMultiOptions());
                    echo '<label>Способ оплаты:</label> ' . $payment;
                    if ($payment == 'Оплата картой') {
                    	echo "<font color='red'><b> (состав заказа менять нельзя)</b></font>";
                    }
                    $pm->setDecorators(array('ViewHelper'));
                    $pm->setAttrib('style', 'display:none;');
                    echo $pm; ?>
                </td>
				<td>&nbsp;
		    		
				</td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
	<legend>Адрес доставки</legend>
	<table cellpadding="0" cellspacing="0" border="0" class="orderedit">
	    <tr>
		<td>
			<?php 
			$input = new Zend_Form_Element_Text('city');
			$input->setRequired(1);
			$input->setLabel('Город:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getCity());
			$input->setAttrib('name', 'city');
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}

			$input->setAttrib('autocomplete', 'off');
			$input->setAttrib('id', 'suggest_city');
			$input->setAttrib('class', 'crud_form_suggest');

			$rel = '';
			if ($delivery->getCity()) {
				$city = CitiesPeer::getInstance()->findByName($delivery->getCity())->current();
				if ($city) {
					$rel = $city->getId();
				}
			}

			$input->setAttrib('rel', $rel);
			echo $input;
			?>
		    <div class="suggest_result" style="display:none;"></div>
		</td>
		<td>
			<?php 
			$input = new Zend_Form_Element_Text('street');
			$input->setRequired(1);
			$input->setLabel('Улица:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getStreet());
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}

			$input->setAttrib('autocomplete', 'off');
			$input->setAttrib('id', 'suggest_street');
			$input->setAttrib('class', 'crud_form_suggest');
			echo $input;
			?>
			<div class="suggest_result" style="display:none;"></div>
		</td>

		<td>
			<?php 
			$input = new Zend_Form_Element_Text('home');
			$input->setRequired(1);
			$input->setLabel('Дом:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getHome());
			$input->setAttrib('style', 'width:50px;');
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}
			
			echo $input;
			?>
		</td>
		<td>
			<?php 
			$input = new Zend_Form_Element_Text('corps');
			$input->setLabel('Корпус:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getCorps());
			$input->setAttrib('style', 'width:30px;');
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}
			
			echo $input;
			?>
		</td>
		<td>
			<?php 
			$input = new Zend_Form_Element_Text('porch');
			$input->setLabel('Подъезд:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getPorch());
			$input->setAttrib('style', 'width:30px;');
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}
			
			echo $input;
			?>
		</td>
		<td>
			<?php 
			$input = new Zend_Form_Element_Text('level');
			$input->setLabel('Этаж:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getLevel());
			$input->setAttrib('style', 'width:30px;');
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}
			
			echo $input;
			?>
		</td>
		<td>
			<?php 
			$input = new Zend_Form_Element_Text('flat');
			$input->setLabel('Квартира:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			$input->setAttrib('default', $delivery->getFlat());
			$input->setAttrib('style', 'width:40px;');
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}
			
			echo $input;
			?>
		</td>
		<td>
			<?php 
			$input = new Zend_Form_Element_Select('metroId');
			$input->setLabel('Метро:');
			$input->setDecorators(array('ViewHelper', 'Label'));
			
			$mPeer = MetroPeer::getInstance();
			$mSelect = $mPeer->select();
			$mSelect->order('name');
			$mRowset = $mPeer->fetchAll($mSelect);
			$metros = array();
			foreach ($mRowset as $mRow) {
				$metros[$mRow->getId()] = $mRow->getName();
			}
			$input->addMultiOption(null);
			$input->addMultiOptions($metros);
			
			$input->setAttrib('default', $delivery->getMetroId());
			if (!$order->isModifiedAvailable()) {
				$input->setAttrib('readonly', 'readonly');
			}
			
			echo $input;
			?>
		</td>
	    </tr>
	    <tr>
		<td colspan="7">
		    <?php $form->delivery_comment->class = '';echo $form->delivery_comment; ?>
		</td>
	    </tr>

	</table>
    </fieldset>
    <fieldset>
	<legend>Логистический оператор</legend>
	<table cellpadding="0" cellspacing="0" border="0" class="orderedit">
	    <tr>
			<td>
				<label class="required" for="operator_id">Оператор</label>				
				<select id="operator_id" name="operator_id">
				<option label="" value=""></option>
				<?php
			        $order_operator = DeliveryService::getInstance()->getActiveOperators();
					/* @var $operator OrderOperatorRow */
					foreach($order_operator as $operator)
					{
						if ($order->getOperatorId() == $operator->getId()) {
							echo '<option selected="selected" label="'.$operator->getName().'" value="'.$operator->getId().'">'.$operator->getName().'</option>';
						} else {
							echo '<option label="'.$operator->getName().'" value="'.$operator->getId().'">'.$operator->getName().'</option>';
						}					
					}					
			    ?>
				</select>
			    <?php //echo $form->operator_id; ?>
			</td>
			<td>
			    <?php
			    	$form->executed_at->class = '';
					echo $form->executed_at; 
			    ?>
			</td>
			<td>
			    <?php echo $form->delivery_time_id; ?>
			</td>
			<td>
				<?php
					$input = new Zend_Form_Element_Checkbox('inMkad');
					$input->setLabel('В черте города?');
					$input->setDecorators(array('ViewHelper', 'Label'));
					$input->setAttrib('default', $delivery->getInMkad());
					$input->setAttrib('name', 'inMkad');
					$input->setAttrib('onclick', 'calculateTotal();');
					if(!$order->getId()){

					}elseif($order->getOrderStatusId() != $placed->getId()){
						$input->setAttrib('disabled', 'disabled');
					}

					echo $input;
				?>
			</td>
	    </tr>
	</table>
    </fieldset>
	
	<?php 
	if($order->getTypeDiscount() == 1 || $order->getTypeDiscount() == 2){
	$user_name = adminUserPeer::getInstance();
	$select_name = $user_name->select()->where('id = ?', $order->getEditName());
	$name = $user_name->fetchRow($select_name);

	if ($order->getTypeDiscount() == 1){
		echo '<div style="font-weight:bold; margin-top: 3px; margin-bottom: 3px;"><i style="color: red;">* </i> на этот заказ была применена скидка <i style="color: red;">'.$order->getPercent().'% </i> , '.$order->getTimeUpdatePrice().' | <i style="color: red;">Цена со скидкой '.$order->getTotalCost().'</i> | '.$name['name'].'.</div>';
	}else if($order->getTypeDiscount() == 2){
    	echo '<div style="font-weight:bold; margin-top: 3px; margin-bottom: 3px;"><i style="color: red;">* </i> на этот заказ цены были проставлены вручную, '.$order->getTimeUpdatePrice().' | <i style="color: red;">Новая цена '.$order->getTotalCost().'</i> | '.$name['name'].'.</div>';
	;}
	}
	?>


	<?php 
	echo $this->render('call-center/_products.phtml'); 
	$deliveryCostElement = $form->getElement('delivery_cost');
   	$deliveryCostElement->setDecorators(array('ViewHelper'));
   	$deliveryCostElement->setAttrib('style', 'display:none;');
   	$deliveryCostElement->setAttrib('id', 'delivery_cost');
   	echo $deliveryCostElement;
	?>
	<br>
	
	<?php if(isset($id)){ 
	
	//$id 
		
		$foreig_select =  ForeignCouponCode2orderPeer::getInstance()->select()->setIntegrityCheck(false)
						->joinLeft('foreign_coupon_code',ForeignCouponCodePeer::ID. ' = '.ForeignCouponCode2orderPeer::CODE_ID,array('code'))
					    ->joinLeft('foreign_coupon',ForeignCouponCodePeer::COUPON_ID.' = '.ForeignCouponPeer::ID,array('name as for_name','size_discount'))
						->joinLeft('product',ProductPeer::ID.' = '.ForeignCouponCode2orderPeer::PRODUCT_ID ,array('name as prod_name', 'internal_id'))
						->where(ForeignCouponCode2orderPeer::ORDER_ID.' = ?',$id);
		
		$foreig_query = ForeignCouponCode2orderPeer::getInstance()->fetchAll($foreig_select);
		if(count($foreig_query))
		{
	
			echo '<p style="font-size: 13pt;"><b>Код купона: </b>'.$foreig_query[0]->code.'<b>, наименование купона: </b>'. $foreig_query[0]->for_name.'</p>';
			echo'<table style="width: 500px; border-collapse:  collapse; border-spacing: 2px; text-align: center;">';
			echo '<tr>';
				echo '<td style="padding: 5px; border:1px solid black; width: 100px">Код товара</td>';
				echo '<td style="padding: 5px; border:1px solid black">Наименование</td>';
				echo '<td style="padding: 5px; border:1px solid black">Скидка</td>';
			echo '</tr>';
		 
			foreach($foreig_query as $fq)
			{			
				echo '<tr>';
					echo '<td style="padding: 5px; border:1px solid black">'. $fq->internal_id .'</td>';
					echo '<td style="padding: 5px; border:1px solid black; text-align: left;">'. $fq->prod_name .'</td>';
					echo '<td style="padding: 5px; border:1px solid black">'. $fq->size_discount .'</td>';
				echo '</tr>	';
			}			
			echo '</table>';

		 } 
	
	} 
	 ?>
	<br>
	<?php
			
	if($order->getId()){
		$reminder = Order2ProductPeer::getInstance();
		$select = $reminder->select();
		$select->setIntegrityCheck(false);
		$select->join('product', '`product`.`id` = `order2product`.`product_id`', array('product_name'=>'name'));
		$select->where(Order2ProductPeer::ORDER_ID, $order->getId());
		$select->where('`product`.`days_end` > "0"');
		$result = $reminder->fetchAll($select);
		
		if(count($result))
				echo '<div id="reminderblock" >';
		else
				echo '<div id="reminderblock" style="display:none">';
				
		$input = new Zend_Form_Element_Checkbox('reminder');
		$input->setDecorators(array('ViewHelper', 'Label'));
		$input->setAttrib('default', $order->getReminder());
		$input->setAttrib('style','margin-right: 5px;display:block; margin-top:1px; float:left;');
		$input->setAttrib('name', 'reminer');
		echo $input;
		echo 'Получить напоминание о повторной покупке следующих товаров?(требуется указать e-mail)';
		echo '</div>';
		
		echo "<ul id='list_reminder' type='1' style='margin-left: 15px;'>";
		if(count($result)){
		
			
		
			echo "<br><br>";
	
			
			if(count($result) > 0){
				foreach($result as $item)
				{
					echo '<li>'.$item['product_name'].'</li>';
				}
			}
		
		
		}
			echo "</ul>";
	}else{
		echo "<br><br>";
		echo "<ul id='list_reminder' type='1' style='margin-left: 15px;'>";
		echo "</ul>";
	}
	?>
	
	
	
    
    <h3 style="margin:15px 0 10px 0">Комментарии операторов к заказу</h3>
    <p class="comment" id="comments">
    <?php 
	    if ($order->getId()) {
			echo $this->partial('call-center/_comments.phtml', array('order' => $order));
	    }
	    ?>
    </p>
    <p class="comment">
    <textarea name="operator_comment" id="operator_comment"></textarea><br />
    <?php 
    $url = $this->url(array(
    	'module' => 'admin', 
    	'controller' => 'call-center', 
    	'action' => 'add-comment',
    	'id' => $order->getId(),
    ), null, true);
    
  	if ($order->getId()) {
    	echo "<input type='button' id='add_comment' value='Добавить комментарий' url='$url' />";
    }
    ?>
    </p>
    
    <hr style="margin-bottom:40px;">
<div style="margin:3px;">

	<?php 
	
	$unverified = OrdersService::getInstance()->getOrderStatusByKey(OrdersService::STATUS_ORDER_UNVERIFIED);
	if ($order->isModifiedAvailable() || $order->getOrderStatusId() == $unverified->getId()) {
		if ($order->getId()) {
    		echo '<input name="submit" value="Оформить" type="submit" /> &nbsp; ';
		}
	}
	if ($order->getId()) {
		if ($order->isModifiedAvailable()) {
			echo "<input name='change' type='submit' value='Изменить' /> &nbsp; ";
		} else {
			echo "<input name='exit' type='submit' value='Не изменять' />";
		}
	} else {
		echo "<input name='change' type='submit' value='Создать заказ' /> &nbsp; ";
	}
	
	if (!$order->isCanceled() && $order->getId()) {
		echo "<input name='cancel' type='submit' value='Аннулировать' /> &nbsp; ";
	}
	
	if(!$order->isCanceledCopy() && $order->getId() && !$order->isCanceled()){
		$discount = CouponService::getInstance()->restoreCupon($order);
		if(!$discount){
			echo "<input name='canceled_copy' type='submit' value='Отменить (содержит копию)' /> &nbsp; ";
		}
	}
	if ($order->getId()) {
		echo '<input name="copy"  type="submit" value="Сделать копию" /> &nbsp; ';
	}
		
if (!$registered) {
		for ($i = 0; $i < 30; $i++) echo "&nbsp;";
		echo "<a href='#' id='create_user'>[создать пользователя]</a>";
	}
	echo '<br />';
	$uncall = OrdersService::getInstance()->getOrderStatusByKey('uncall');
	if ($order->getId() && $order->isModifiedAvailable() && $order->getOrderStatusId() != $uncall->getId()) {
		echo "<input name='uncall' type='submit' value='Не дозвонились' /> &nbsp; ";
	}

	if ($order->getId()) {
		echo "<input name='exit' type='submit' value='Выйти из заказа' />";
	}
	
	?>
	
</form>

<style type="text/css">
p.comment label {
	display: block;
	font-weight: bold;
}
</style>

